package com.jonah.sqlsession;

import com.jonah.config.XmlConfigBuilder;
import com.jonah.pojo.Configuration;
import org.dom4j.DocumentException;

import java.beans.PropertyVetoException;
import java.io.InputStream;

/**
 * @Author: Jonah.Chen
 * @Date: 2020/8/5 21:57
 * @Description:
 */
public class SqlSessionFactoryBuilder {

    public SqlSessionFactory build(InputStream in) throws DocumentException, PropertyVetoException {
        // 1.使用dom4j解析配置文件, 将内容封装到Configuration中
        XmlConfigBuilder configBuilder = new XmlConfigBuilder();
        Configuration config = configBuilder.parseConfig(in);

        // 2.创建SqlSessionFactory对象, 生产SqlSession
        DefaultSqlSessionFactory sqlSessionFactory = new DefaultSqlSessionFactory(config);

        return sqlSessionFactory;
    }

}